from rest_framework.viewsets import GenericViewSet
from rest_framework.filters import OrderingFilter
from django_filters import rest_framework as filters
from mixins import MyListModelMixin, MyDestroyModelMixin, MyCreateModelMixin, MyUpdateModelMixin
from .filter import DepartmentProductFilter
from .serializers import DepartmentSerializers
from .models import Departments
from auth import JwtTokenAuthentication
from pagination import MyPageNumberPagination


class DepartmentViews(MyListModelMixin, MyDestroyModelMixin, MyCreateModelMixin, MyUpdateModelMixin, GenericViewSet):
    # 一个部门多个人 此功能未完成
    queryset = Departments.objects.filter(is_deleted=False).all().order_by("-id")
    authentication_classes = [JwtTokenAuthentication]
    filter_backends = [OrderingFilter, filters.DjangoFilterBackend]
    serializer_class = DepartmentSerializers
    pagination_class = MyPageNumberPagination
    filterset_class = DepartmentProductFilter
    ordering_fields = ['id']
    filter_fields = ('name', 'updated_at', 'created_at')
